﻿using System.Data;
using System.Data.Entity;
using System.Linq;

namespace HotelRegistrationSystem.DAL
{
    public static class AccountDAL
    {
        public static DbSet<User> GetUsers()
        {
            HotelRegistrationSystemEntities db = new HotelRegistrationSystemEntities();
            DbSet<User> users = db.Users;
            return users;
        }

        public static User GetUser(string userName)
        {
            HotelRegistrationSystemEntities db = new HotelRegistrationSystemEntities();
            User user = db.Users.FirstOrDefault(x => x.UserName == userName);
            if (user == null)
            {
                throw new ObjectNotFoundException("User is not logged or does not exist.");
            }
            return user;
        }

        public static bool IsOwnerOfTheHotel(this User user, int hotelId)
        {
            Hotel hotel = HotelDAL.GetHotel(hotelId);
            if (hotel != null && hotel.UserId == user.UserId)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}